package com.example.venue_reservation_service.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.CellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class LocalTimeStringConverter implements Converter<LocalTime> { // 类名改为更明确的LocalTimeStringConverter

    @Override
    public Class<LocalTime> supportJavaTypeKey() {
        return LocalTime.class; // 修改为支持LocalTime类型[8](@ref)
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING; // Excel中存储为字符串
    }

    // LocalTime转Excel字符串
    @Override
    public WriteCellData<?> convertToExcelData(LocalTime localTime, ExcelContentProperty contentProperty,
                                               GlobalConfiguration globalConfiguration) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); // 时间格式调整为时分秒
        String cellValue = formatter.format(localTime);
        return new WriteCellData<>(cellValue); // 直接返回字符串类型的CellData[6](@ref)
    }
}
